<template>
  <div>
    <el-dialog title="提示" v-model="visible" width="30%" @close="onClose">
      <template #title>
        <p class="dialog-title">标题</p>
      </template>
      <strong>弹窗模板</strong>
      <template #footer>
        <span class="dialog-footer">
          <el-button size="mini" @click="onClose">取 消</el-button>
          <el-button size="mini" type="primary" @click="onConfirm"
            >确 定</el-button
          >
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { defineComponent, toRefs, reactive, watch } from "vue";
interface Props {
  dialogVisible: boolean;
}
interface State {
  visible: boolean;
}
export default defineComponent({
  name: "Dialog",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  setup(props, context) {
    const { dialogVisible } = toRefs(props as Props);
    const parent = { ...context };
    const state = reactive<State>({
      visible: dialogVisible.value,
    });
    watch(
      dialogVisible,
      (newValue) => {
        state.visible = newValue;
      },
      { immediate: true }
    );
    const onClose = () => {
      parent.emit("update:dialogVisible", false);
    };
    const refreshTable = () => {
      parent.emit("refresh-table", "弹窗操作");
    };
    return {
      ...toRefs(state),
      onClose,
      refreshTable
    };
  },
});
</script>
<style lang="scss" scoped>
.dialog-title {
  font-size: 0.1rem;
  font-weight: bold;
  text-align: center;
}
</style>